const mysql = require('mysql2');
const config = require('./config');

const pool = mysql.createPool({
  host: config.MYSQL_HOST,
  port: config.MYSQL_PORT,
  database: config.MYSQL_DB,
  user: config.MYSQL_USER,
  password: config.MYSQL_PASSWORD,
  waitForConnections: true,
  connectionLimit: config.MYSQL_CONNECT_LIMIT,
  queueLimit: 0,
});

pool.getConnection((err, con) => {
  con.connect((err) => {
    if (err) {
      console.log('mysql connect fail:', err);
    }else{
      console.log('mysql connect success')
    }
  });
});

module.exports = pool.promise();
